import urllib.request
import random
import ssl

ssl._create_default_https_context = ssl._create_unverified_context
url = 'http://www.baidu.com/s?wd=ip'

headers = {
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
}
# 简易版代理池
proxies_list = [
    {"http": "118.24.219.151:16817"},
    {"http": "118.24.219.151:16817"},
]

# 随机一个代理ip
proxies = random.choice(proxies_list)

request = urllib.request.Request(url=url, headers=headers)

handler = urllib.request.ProxyHandler(proxies=proxies)

opener = urllib.request.build_opener(handler)

response = opener.open(request)

content = response.read().decode('utf-8')
print(content)